package suites.tween {
	import org.flexunit.asserts.assertTrue;
	import org.flexunit.asserts.fail;
	import org.flexunit.async.Async;
	import org.splink.library.queue.Progress;
	import org.splink.library.queue.QEvent;
	import org.splink.library.tween.QTween;

	import flash.display.Sprite;
	import flash.events.Event;

	/**
	 * @author Max Kugland
	 */
	public class AbstractTweenTest {
		private var _handleEventFnc : Function;
		protected var _tween : QTween;
		protected var _target : Sprite;

		[Before]
		public function before() :void {
			_tween = new QTween(_target = new Sprite());
			_tween.register(QEvent.COMPLETE, onComplete);			_tween.register(QEvent.PROGRESS, onProgress);
		}
		
		final protected function handleAsync(timeout : int) : Function {
			return _handleEventFnc = Async.asyncHandler(this, function():void {
			}, timeout, null, handleTimeout);
		}

		final protected function handleTimeout( passThroughData : Object ) : void {
			fail("Timeout reached before event");			
		}

		final protected function onProgress(e : QEvent) : void {
			var p : Progress = e.progress;
			assertTrue(p.percent <= 100 && p.percent >= 0);
//			trace(e.id + " -> " + p.percent)
		}

		final protected function onComplete(e : QEvent) : void {
			_handleEventFnc(new Event(Event.COMPLETE));
		}
	}
}
